/**
 * Created by Xiaoming on 2017/8/29.
 */
angular.module('module.auth')
    .controller('SettingsController', SettingsController);

SettingsController.$inject = ['user','AuthService','FileUpload'];
function SettingsController(user,AuthService,FileUpload) {
    var vm = this;
    vm.user = user;
    vm.progressPercentage = 0;
    vm.submit = submit;
    vm.uploadLogo = uploadLogo;
    //提交更新
    function submit(user){
        AuthService.updatebyid(user,function(data){
            setCookie("_userName",data.nickname);
            setCookie("_userLogo",data.logo);
            input_alert("更新成功！");
            setTimeout(function(){
                window.history.back();
            },2000)
        },function(error){
            input_alert("更新失败！稍后重试！");
        })
    }
    //图片上传
    function uploadLogo(file){
        FileUpload.uploadFileToUrl(file,progress).then(function(data){
            vm.user.logo = data.faddress;
            input_alert("上传成功！");
        });
        function progress(evt){
            vm.progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
            $(".progress-bar").css({width:vm.progressPercentage+"%"});
        }
    }
}